//放大镜选择客户
function goCustomer(obj,customerName,customerID){
	var url = "";
	if(window.ActiveXObject){
		url = "/Customers/selectOnly";
	}else{
		url = "/Customers/selectCustomerOnly";
	}
	
	var rd=window.showModalDialog(url,"","dialogWidth=500px;dialogHeight=400px;");
	if (rd == undefined) {
        rd = window.returnValue;
    }
	
	if(rd!=undefined && rd!=""){
	 	$.getJSON("/Customers/findCustomerById",{id:rd},function(data){
	 		if(data!="error"){
	 			$("#"+customerName).val(data.shortName);
	 			$("#"+customerID).val(data.id);
	 		}else{
	 			alert("该客户不存在！");
	 		}
	 	});
	}
}

//客户唯一性检查
function findCustomer(customerName){
	if(customerName!=null&&customerName!=""){
		$.get("/Customers/isCustomer",{customerName:customerName},function(data){
			if(data=="error"){
				alert("系统不存在该客户!");
				$("#object_customerName").val("");
				
			}else{
				$("#customer_ID").val(data.id);
				//补全收货人，收获地址，联系方式等信息
				$("#receiver").val(data.receiver);
				$("#address").val(data.addr);
				$("#contact").val(data.receiverTel);
				$("#object_user").val(data.user.id);
				$("#object_user_name").val(data.user.truename);
			}
		});
	}
	
}

//客户的自动补全
customer_options = {
	url:"/Customers/getName",
	formateItem:customerFormateItem,
	selectItem:customerSelectItem
}

function customerFormateItem(row) {
	return row.shortName;
}

function customerSelectItem(obj,row) {
	$(obj).val(row.shortName);
	$("#customer_ID").val(row.id);
}


function lookCustomer(customerID){
	var customerId = $("#"+customerID).val();
	if (customerId == null || customerId == "") {
		alert("请输入客户名称");
	} else {
		open_dialog("/Customers/detail?id=" + customerId, 900, 750);
	}
}

//发货人的自动补全
sender_options = {
	url:"/DeliveryNotices/getSender",
	formateItem:senderFormateItem,
	selectItem:senderSelectItem
}

function senderFormateItem(row) {
	return row.sender+" "+row.carNumber+" "+row.senderPhone;
}

function senderSelectItem(obj,row) {
	$(obj).val(row.sender);
	$("#carNumber").val(row.carNumber);
	$("#senderPhone").val(row.senderPhone);
}

/**
 * 
 * @param obj
 * @param total
 * @param defaultValue
 */
function totalAll(obj,total,defaultValue){
	var sum = parseFloat(defaultValue);
	
	obj.each(function() {
		if ($(this).val() != "") {
			sum += parseFloat($(this).val());
		}
	});
	total.val(sum.toFixed(2));
}

